package pe.edu.unmsm.fisi.sisconteg.repository.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import pe.edu.unmsm.fisi.sisconteg.domain.model.Empresa;
import pe.edu.unmsm.fisi.sisconteg.repository.dao.EmpresaDAO;

@Repository
public class EmpresaDAOImpl implements EmpresaDAO {

	@Autowired
	private SessionFactory sessionFactory;

	@SuppressWarnings("unchecked")
	@Override
	public List<Empresa> listEmpresas() throws DataAccessException {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(
				Empresa.class);
		return criteria.list();
	}

	@Override
	public void crearEmpresa(Empresa empresa) throws DataAccessException {
		sessionFactory.getCurrentSession().persist(empresa);
	}

}
